package com.tmsps.common.config;

import com.tmsps.common.config.prop.Ne4CommonProperties;
import com.tmsps.common.filter.AddResponseHeaderFilter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 过滤器配置类
 * @author jiangtao
 */
@Configuration
@EnableConfigurationProperties(Ne4CommonProperties.class)
public class FilterConfiguration {

    @Bean
    public FilterRegistrationBean testFilterRegistration(Ne4CommonProperties prop) {
        AddResponseHeaderFilter headerFilter = new AddResponseHeaderFilter(prop.getHeader());
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(headerFilter);
        registration.addUrlPatterns("/*"); //
        registration.setName("HeaderFilter");
        registration.setOrder(1);
        return registration;
    }
}